package interpreterPattern;

/**
 * 非终结符表达式
 */
public class Plus extends Expression{

    // +号左边的表达式
    private Expression left;
    // +号右边的表达式
    private Expression right;

    public Plus(Expression left, Expression right) {
        this.left = left;
        this.right = right;
    }

    //
    @Override
    public int interpret(Context context) {
        return left.interpret(context) + right.interpret(context);
    }

    @Override
    public String toString() {
        return "(" + left.toString() + " + " + right.toString() + ")";
    }
}
